<script>
	import eonfox from '@/components/eonfox/eonfox.js';
	import fns from '@/components/eonfox/fns.js';
	import polling from '@/components/eonfox/polling.js';
	// #ifdef H5
	let jweixin = require('jweixin-module');
	let url_href = location.href;
	// #endif
	var ef = new eonfox();
	var downloadTask = null;
	export default {
		data() {
			return {
				 message:'',//是否认证
				 sjID:''   ,//商家id
				 messageID:'',//消息id
				 ypsrc:'',
				
			};
		},
		
		onLaunch: function () {
			// #ifdef H5
		   console.log(jweixin,'等待')
		    // this.getuserToken()
		   // #endif
		   
		},
		onShow: function () {
			// #ifdef MP-WEIXIN
			const updateManager = wx.getUpdateManager()

			updateManager.onCheckForUpdate(function (res) {
			  // 请求完新版本信息的回调
			  console.log(res.hasUpdate)
			})

			updateManager.onUpdateReady(function () {
			  wx.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启应用？',
				success(res) {
				  if (res.confirm) {
					// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
					updateManager.applyUpdate()
				  }
				}
			  })
			})

			updateManager.onUpdateFailed(function () {
			  // 新版本下载失败
			})
			// #endif
		},
		onHide: function () {
			// console.log('App Hide')
		},
		methods:{
			//h5授权信息
			getuserToken(){
				let that = this;
				// console.log(that.userinfo)
				// return
				// if(){}
									
						
							ef.submit({
								request:{
									token:['SESSIONWEIXINACCESSTOKEN'],
									// userinfo:['USERSELF']
								},
								callback: function(data) {
									let dataToken=fns.checkError(data,'token',function(errno,error){
										uni.showToast({
											title: '请先确认微信授权',
											icon:'none'
										})
									})
									
									// uni.setStorage({
									// 	key:'weixitoken',
									// 	data:data
									// })
									// console.log(dataToken.token,'123456')
									
									if(dataToken){																				
										ef.submit({
											request:{
												che:['SESSIONWEIXINCHECKOAUTH',[{"unionid":dataToken.token.unionid}]]
											},
											callback:function(datas){
												// console.log(datas.data.che.state)
												if(datas.data.che.data.state==1){
													ef.submit({
														request:{
															bind:['SESSIONWEIXINSAVEWXINFO',
																[
																	'web',
																	{unionId:dataToken.token.unionid,access_token:dataToken.token.access_token,openid:dataToken.token.openid}
																]
															]
														},
														callback:function(datas2){
															// console.log(datas2.data.bind.data)
															try {
															    uni.setStorageSync('oauth_id', datas2.data.bind.data.oauth_id);
															} catch (e) {
															    console.log(e)
															}
														}
													})
												}else{
													console.log('已授权过了',datas.data.che)
													// try {
													//     uni.setStorageSync('oauth_id', datas2.data.bind.data.oauth_id);
													// } catch (e) {
													//     console.log(e)
													// }
												}
											}
										})
										
									}else{
										console.log('location', location.href);
										
										//当 ACCESSTOKEN 不存在
										ef.left_token(function(left_token){
											var notify_url = encodeURIComponent(location.href);
											var url = ef.api_server_url+"?"+encodeURI('data=[["SESSIONWEIXINAUTHORIZE",[{"notify_url":"'+notify_url+'"}]]]')+"&token="+left_token;
											console.log(url);
											location.href = url;
										});
										
										
									}								
									
								}
							})
						
						
						
					
				
				
			},
				
			}
		
	}
</script>

<style>
	.ml10{
		margin-left: 10px;
	}
	/* 超出部分省略号隐藏 */
	.ov1{
			overflow:hidden; 
	text-overflow:ellipsis;
	-webkit-box-orient:vertical;
	-webkit-line-clamp:1; 
		}
	.ov2{
		overflow:hidden; 
text-overflow:ellipsis;
display:-webkit-box; 
-webkit-box-orient:vertical;
-webkit-line-clamp:2; 
	}
	.ov4{
			overflow:hidden; 
	text-overflow:ellipsis;
	display:-webkit-box; 
	-webkit-box-orient:vertical;
	-webkit-line-clamp:4; 
		}
	/*每个页面公共css */
</style>
